import random

def get100(z ,i):
    num = round(z / i, 2)
    percentage = num * 100
    # 将百分比转换为字符串并添加百分号后缀
    result = "{:.2f}%".format(percentage)
    return result

if __name__ == '__main__':
    i = 0
    z = 0
    while True:
        binary_number = ''.join(str(random.randint(0, 1)) for _ in range(4))
        print('二进制数：'+binary_number)
        decimal = int(binary_number, 2)
        user_input = input("请输入二进制对应的十进制：")
        i = i+1
        if user_input == str(decimal):
            z = z +1
            b = get100(z,i)
            print(f"回答正确  回答{i}次 正确率{b}\n ")
        else:
            b = get100(z, i)
            print(f"回答错误 答案是:{decimal} 回答{i}次 正确率{b}\n")
